package sunstar.com.xq.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.group_rank_adapter.*
import sunstar.com.xq.R
import sunstar.com.xq.util.ViewInitUtil

/**
 * Created by Sun.Star on 2017/6/21.
 */
class GroupRankAdapter(var context: Context) : RecyclerView.Adapter<GroupRankAdapter.GroupRankViewHolder>() {
    override fun onBindViewHolder(holder: GroupRankViewHolder?, position: Int) {

        if(position == 0 ){holder!!.rankTitle.text ="魁首"}

        if(position == 1 )
            holder!!.rankTitle.text ="榜眼"
            if(position == 2 )
                holder!!.rankTitle.text ="探花"
        Picasso.with(context).load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1498049759422&di=fdb49927fa1a351220cb883d04df8c15&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01286e57dd53e40000012e7eb5f1e2.jpg%40900w_1l_2o_100sh.jpg").into(holder!!.img)

    }

    override fun getItemCount(): Int = 5

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): GroupRankViewHolder
    = GroupRankViewHolder(LayoutInflater.from(context).inflate(R.layout.group_rank_adapter,parent,false))

    class GroupRankViewHolder(itemview:View) : RecyclerView.ViewHolder(itemview){
        val viewInit by lazy {
           ViewInitUtil(itemView)
        }
        val rankTitle by lazy {
            viewInit.getView<TextView>(R.id.group_rank_name)
        }
        val groupName by lazy{
            viewInit.getView<TextView>(R.id.group_rank_group_name)
        }
        val img by lazy {
            viewInit.getView<ImageView>(R.id.group_rank_img)
        }

    }

}